home *** CD-ROM | disk | FTP | other *** search
- Public Class TransparentForm
- Inherits System.Windows.Forms.Form
-
- #Region " Windows Form Designer generated code "
-
- Public Sub New()
- MyBase.New()
-
- 'This call is required by the Windows Form Designer.
- InitializeComponent()
-
- 'Add any initialization after the InitializeComponent() call
-
- End Sub
-
- 'Form overrides dispose to clean up the component list.
- Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
- If disposing Then
- If Not (components Is Nothing) Then
- components.Dispose()
- End If
- End If
- MyBase.Dispose(disposing)
- End Sub
- Friend WithEvents Label1 As System.Windows.Forms.Label
- Friend WithEvents btnClose As System.Windows.Forms.Button
-
- 'Required by the Windows Form Designer
- Private components As System.ComponentModel.Container
-
- 'NOTE: The following procedure is required by the Windows Form Designer
- 'It can be modified using the Windows Form Designer.
- 'Do not modify it using the code editor.
- <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
- Me.Label1 = New System.Windows.Forms.Label()
- Me.btnClose = New System.Windows.Forms.Button()
- Me.SuspendLayout()
- '
- 'Label1
- '
- Me.Label1.BackColor = System.Drawing.Color.Red
- Me.Label1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
- Me.Label1.Location = New System.Drawing.Point(160, 103)
- Me.Label1.Name = "Label1"
- Me.Label1.Size = New System.Drawing.Size(192, 40)
- Me.Label1.TabIndex = 0
- Me.Label1.Text = "Drag this form by clicking anywhere on its surface"
- '
- 'btnClose
- '
- Me.btnClose.BackColor = System.Drawing.Color.BurlyWood
- Me.btnClose.Location = New System.Drawing.Point(208, 175)
- Me.btnClose.Name = "btnClose"
- Me.btnClose.Size = New System.Drawing.Size(104, 40)
- Me.btnClose.TabIndex = 1
- Me.btnClose.Text = "Close "
- '
- 'TransparentForm
- '
- Me.AutoScaleBaseSize = New System.Drawing.Size(7, 17)
- Me.BackColor = System.Drawing.Color.Orange
- Me.ClientSize = New System.Drawing.Size(512, 318)
- Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnClose, Me.Label1})
- Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 11!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
- Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
- Me.Name = "TransparentForm"
- Me.ResumeLayout(False)
-
- End Sub
-
- #End Region
-
- ' in the Paint event we draw the elliptical form
-
- Private Sub TransparentForm_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
- ' make Black the transparent color, so that only the ellipse is visible
- Me.TransparencyKey = Color.Blue
-
- ' Create a Brush of same color as backcolor
- Dim b As New SolidBrush(Me.BackColor)
-
- ' draw a blue rectangle over the entire form.
- e.Graphics.FillRectangle(Brushes.Blue, Me.ClientRectangle)
- ' draw an ellipse of original backcolor
- e.Graphics.FillEllipse(b, Me.ClientRectangle)
- ' create a border
- e.Graphics.DrawEllipse(Pens.Black, Me.ClientRectangle)
-
- ' destroy the Brush
- b.Dispose()
- End Sub
-
- ' API constants for subclassing
- Private Const WM_NCHITTEST As Integer = &H84
- Private Const HTCAPTION As Integer = 2
- Private Const HTCLIENT As Integer = 1
-
- ' we subclass the form so that the user can move it
- ' by clicking anywhere on its surface
-
- Protected Overrides Sub WndProc(ByRef m As Message)
- ' let the base form process this message
- MyBase.WndProc(m)
-
- Select Case m.Msg
- Case WM_NCHITTEST
- ' if on client area, make Windows believe it's on caption
- If m.Result.ToInt32 = HTCLIENT Then
- ' the only way to assing an IntPtr
- m.Result = New IntPtr(HTCAPTION)
- End If
- End Select
- End Sub
-
- ' just close the form
-
- Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
- Me.Close()
- End Sub
- End Class
-